<style type="text/css">
#main-table-box-read{
	padding:0 !important; 
}

#main-table-box-read #field-hasil,
#main-table-box-read #field-uraian_kegiatan{
	background:  #f1f1f1;
    border: 1px solid #ccc;
    padding: 1em;
    text-align: justify;
    width: 400px !important;
}
.form-display-as-box{
	width: 136px;
	/*text-align: right;*/
}
#field-password,#field-confirm_password,#field-nip,#field-id_group{
	width:200px !important;
}
#field-nama_lengkap{
	width: 250px;
}
#field-waktu_mulai,
#field-waktu_selesai{
	width: 100px;
}
.flexigrid div.form-div{
	margin: 0 auto;
    padding: 16px 0 0;
 /*   width: 426px;*/
}
.flexigrid.crud-form {
    margin-left: auto !important;
    margin-right: auto !important;
/*    width: 500px !important;*/
}
#field-uraian_kegiatan{
	width: 200px;
}
.username-watermark {
 /*   border: 1px solid #dedede;*/
    height: 26px;
    margin-left: 115px;
    margin-top: -1px;
    position: absolute;
    width: 222px;
}
#field-verifikasi{
	/*width: 50px !important;*/
}
#field-hasil{
	width: 98%;
}

table.frmTable {
	border-collapse: collapse;
}
table.frmTable td{
	font-size: 11px !important;
	font-family: Helvetica,​Arial,​sans-serif;
}
table.frmTable td.label{
	font-weight: bold;
}
.ui-dialog{
	z-index: 1003 !important;
}
</style>
<div class="frm-tmp">
	<table border="0" width="100%" class="frmTable" cellpadding="4">
		<tbody>
			<tr>
				<td width="108px" class="label">Nama</td>
				<td>:</td>
				<td width="200px"><div id="nip_selector"><?php echo $nip_selector?></div><u><b id="txt_nama_lengkap"><?php echo $this->LoginInfo->getUserInfo('nama_lengkap')?></b></u></td>
				<td width="20px">&nbsp;</td>
				<td width="108px" class="label">Golongan</td>
				<td>:</td>
				<td width="200px" id="txt_golongan"> <?php echo $this->LoginInfo->getUserInfo('golongan')?></td>
			</tr>
			<tr>
				<td class="label">NIP</td>
				<td>:</td>
				<td><u><b id="txt_nip"><?php echo $this->LoginInfo->getUserInfo('nip')?></b></u></td>
				<td>&nbsp;</td>
				<td class="label">Instansi</td>
				<td>:</td>
				<td id="txt_instansi"><?php echo $this->LoginInfo->getUserInfo('instansi')?></td>
			</tr>
			<tr>
				<td class="label">Jabatan</td>
				<td>:</td>
				<td id="txt_jabatan"><?php echo $this->LoginInfo->getUserInfo('jabatan')?></td>
				<td>&nbsp;</td>
				<td class="label">Atasan</td>
				<td>:</td>
				<td id="txt_atasan"><?php echo $this->LoginInfo->getUserInfo('atasan')?></td>
			</tr>
			<tr>
				<td colspan="7"><hr/></td>
			</tr>
			<!-- FORM -->
			<tr>
				<td class="label">Tanggal Kegiatan</td>
				<td>:</td>
				<td> <span id="tpl_tgl_kegiatan"></span></td>
				<td>&nbsp;</td>
				<td class="label">Hari</td>
				<td>:</td>
				<td><span id="hariTxt"></span></td>
			</tr>
			<tr>
				<td class="label" rowspan="2" valign="top">Uraian Pekerjaan</td>
				<td rowspan="2" valign="top">:</td>
				<td rowspan="2" valign="top"><span id="tpl_uraian_kegiatan"></span></td>
				<td rowspan="2">&nbsp;</td>
				<td class="label"valign="top">Waktu Mulai</td>
				<td valign="top">:</td>
				<td valign="top"><span id="tpl_waktu_mulai"></span></td>
			</tr>
			<tr>
				<td class="label" valign="top">Waktu Selesai</td>
				<td valign="top">:</td>
				<td valign="top"><span id="tpl_waktu_selesai" ></span></td>
			</tr>
			<tr>
				<td class="label" valign="top">Hasil / Output</td>
				<td valign="top">:</td>
				<td colspan="5" valign="top"><span id="tpl_hasil"></span></td>
			</tr>
			<tr id="tr_verifikasi">
				<td class="label" valign="top">Verifikasi</td>
				<td valign="top">:</td>
				<td colspan="5" valign="top"><span id="tpl_verifikasi"></span></td>
			</tr>
			<!-- END OF FORM -->
		</tbody>
	</table>

</div>
<script type="text/javascript">
$(document).ready(function(){

	/*************************************************************************************************/
	// EXCHANGE FOM FIELDS
	var frmTmp = $('.frm-tmp');
	$('#crudForm.frm-aktifitas-pegawai').prepend(frmTmp.html());
	// REMOVE TMP FORM
	frmTmp.remove();

	var fields = ["tgl_kegiatan", "waktu_mulai", "waktu_selesai","hasil","uraian_kegiatan","verifikasi"];
	exchange_field('#crudForm.frm-aktifitas-pegawai',fields);

	setTimeout(function(){

		$('#save-and-go-back-button').focus();
		$('#field-tgl_kegiatan').change(function(){
			display_hari();
		}).trigger('change');

	},300);
	/**************************************************************************************************/

	var tipe_admin 	= '<?php echo $this->LoginInfo->getUserInfo('tipe_admin')?>';
	var oper		= gcConf.state ;
	var grid_mode	= '<?php echo $mode?>' 
	function display_hari()
	{
		var date =  $('#field-tgl_kegiatan').datepicker('getDate');
		//console.log($('#field-tgl_kegiatan'))
		var hari = $.datepicker.formatDate('DD',date);
		$('#field-hari').val(hari);
		$('#hariTxt').text(hari);
	}
	function refine_view()
	{
		var nip = $('#field-nip.readonly_label').text();
		$.getJSON('<?php echo base_url()?>master/pegawai/get_profile/'+nip,function(data){
			if(data.success)
			{
				$('#field-nip.readonly_label').text( nip + ' / ' + data.result.nama);
			}
		});
		var tgl_kegiatan = new Date($('#field-tgl_kegiatan').text());
		var tgl_entry = new Date($('#field-tgl_entry').text());
		console.log(tgl_kegiatan);
		console.log(tgl_entry);

		$('#field-tgl_kegiatan').text($.datepicker.formatDate('dd/mm/yy',tgl_kegiatan));
		$('#field-tgl_entry').text($.datepicker.formatDate('dd/mm/yy',tgl_entry));
	}
	function clear_read_only_value()
	{
		$('#txt_jabatan,#txt_instansi,#txt_golongan,#txt_nip,#txt_atasan').text('')
	}
	switch(tipe_admin)
	{
		// IF SECTION ADMIN
		case 'Lurah':
			// ADD CHANGE HANDLER TO NIP SELECTOR
			$('#nip_selector > select').change(function(){
				var nip_dropdown = $(this).val();
				console.log(this)
				if(!nip_dropdown)
					return false;
				if(nip_dropdown.length > 1)
				{
					$.getJSON('<?php echo base_url()?>master/pegawai/get_profile/'+nip_dropdown,function(data){
						if(data.success)
						{
							$('#txt_jabatan').text(data.result.jabatan);
							$('#txt_instansi').text(data.result.instansi);
							$('#txt_golongan').text(data.result.golongan);
							$('#txt_nip').text(data.result.nip);
							$('#txt_atasan').text(data.result.nama_atasan);
							$('#field-atasan').val(data.result.nip_atasan);
						}
						else
						{
							// RESET READONLY VALUE
							clear_read_only_value();
						}
					});
				}
				else
				{
					clear_read_only_value();
				}
			});

			if(oper == 'Add')
			{
				$('#field-nip').val('<?php echo $this->LoginInfo->getUserInfo('nip')?>')
				$('#field-tgl_entry').val('<?php echo date('d/m/Y')?>');
				$('#tgl_entry_field_box').hide();
				$('#nip_field_box').hide();
				$('#hari_field_box').hide();
				
				$('#verifikasi_field_box').hide();

				
			}
			else if(oper == 'Edit')
			{
				var nip_input = $('#field-nip').val();
				//console.log(nip)
				$('#nip_selector > select').val(nip_input).trigger('change');
				//$('#field-tgl_kegiatan').trigger('change');
				setTimeout(function(){
					display_hari();
				},500);
				$('#tgl_entry_field_box').hide();
				$('#nip_field_box').hide();
				$('#hari_field_box').hide();
			}
			// HIDE TXT NAMA LENGKAP AND CHANGE TO DROPDOWN
			$('#txt_nama_lengkap').hide();
			// HIDE ATASAN FIELD BOX
			$('#atasan_field_box').hide();
			// REMOVE DUPLICATE NIP
			
			clear_read_only_value();
			if(oper != 'Read')
			{
				var ckVerifikasi = '<input type="checkbox" id="ckVerifikasi" />&nbsp;<span id="ckText"></span>';
				$('#field-verifikasi').after(ckVerifikasi);

				$('#field-verifikasi').hide();
				var status_aktif = $('#field-verifikasi').val()=='Ya';

				//console.log($('#field-verifikasi').val())
				setTimeout(function(){
					if(status_aktif)
					{
						$('#ckVerifikasi').attr('checked',true);
						$('#ckText').text('Ya');
					}
					else
					{
						$('#ckText').text('Tidak');
						$('#field-verifikasi').val('Tidak').trigger('change');
					}

					$('#ckVerifikasi').click(function(){
						var status = this.checked ? 'Ya' : 'Tidak';
						//console.log(status)
						$('#field-verifikasi').val(status).trigger('change');
						$('#ckText').text(status);
					});
				},100);

				$('#field-nip').remove();
				// RESET READONLY VALUE
			}
			else // OPER READ MODE
			{
				refine_view();
			}

			if(oper == 'Add')
			{
				if(typeof gcConf.current_nip != 'undefined')
				{
					setTimeout(function(){
					$('#nip_selector > select').val(gcConf.current_nip).trigger('change');
					},500);
				}
			}
			if(oper == 'Read')
			{
				refine_view();
				$('#atasan_field_box').remove()
			}
		break;
		default:
			if(oper == 'Read')
			{
				refine_view();
				$('#atasan_field_box').remove()
			}
		break;


	}

	// console.log(section)

	
	// if(gcConf.state != 'Read')
	// {
	// 	var ckVerifikasi = '<input type="checkbox" id="ckVerifikasi" />&nbsp;<span id="ckText"></span>';
	// 	$('#field-verifikasi').after(ckVerifikasi);

	// 	$('#field-verifikasi').hide();
	// 	var status_aktif = $('#field-verifikasi').val()=='Ya';

	// 	//console.log($('#field-verifikasi').val())
	// 	setTimeout(function(){
	// 		if(status_aktif)
	// 		{
	// 			$('#ckVerifikasi').attr('checked',true);
	// 			$('#ckText').text('Ya');
	// 		}
	// 		else
	// 		{
	// 			$('#ckText').text('Tidak');
	// 			$('#field-verifikasi').val('Tidak').trigger('change');
	// 		}

	// 		$('#ckVerifikasi').click(function(){
	// 			var status = this.checked ? 'Ya' : 'Tidak';
	// 			//console.log(status)
	// 			$('#field-verifikasi').val(status).trigger('change');
	// 			$('#ckText').text(status);
	// 		});
	// 	},100);
	// }
	// // SET DEFAULT

	
	// if(section != 'Lurah')
	// {
	// 	$('#nip_selector').remove();
	// }
	// else
	// {
	// 	//var $('#nip_field_box').remove();
	// 	//get_profile
		
	// }
	// if(gcConf.state == 'Add')
	// {
		
	// 	//$('.form-div').hide();
	// }
	// else if(gcConf.state == 'Edit')// IF EDIT
	// {
	// 	var nip = $('#field-nip').val();
	// 	console.log(nip)
	// 	$('#nip_selector > select').val(nip).trigger('change')
	// }

	// $('#atasan_field_box').hide();

});
</script>